#include <iostream>

using namespace std;
const int N=30,M=30;
int chessman[N][M]= {0};
bool is_clear[N][M]= {false};
int main_45()
{
    int n,m;
    cin>>n>>m;
    for (int i=0; i<n ; i++ )
    {
        for (int j=0; j<m ; j++ )
        {
            cin>>chessman[i][j];
        }
    }
    // label by row
    for (int i=0; i<n ; i++ )
    {
        for (int j=0; j<m-2 ; j++ )
        {
            if ((chessman[i][j]==chessman[i][j+1])&&(chessman[i][j+1]==chessman[i][j+2]))
            {
                is_clear[i][j]=is_clear[i][j+1]=is_clear[i][j+2]=true;
            }
        }
    }
    // label by column
    for (int j=0; j<m ; j++ )
    {
        for (int i=0; i<n-2 ; i++ )
        {
            if ((chessman[i][j]==chessman[i+1][j])&&(chessman[i+1][j]==chessman[i+2][j]))
            {
                is_clear[i][j]=is_clear[i+1][j]=is_clear[i+2][j]=true;
            }
        }
    }
    // clear
    for (int i=0; i<n ; i++ )
    {
        for (int j=0; j<m ; j++ )
        {
            if (is_clear[i][j])
            {
                chessman[i][j]=0;
            }
        }
    }
    // print
    for (int i=0; i<n ; i++ )
    {
        for (int j=0; j<m ; j++ )
        {
            cout<<chessman[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}
